﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows;

namespace WpfApp2
{
    public class BooleanToVisibilityConverter : IValueConverter
    {
        // 将布尔值转换为 Visibility
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue)
            {
                // 如果 parameter 为 "Hidden"，则将 false 转换为 Hidden
                if (parameter?.ToString() == "Hidden" && !boolValue)
                {
                    return Visibility.Hidden;
                }
                return boolValue ? Visibility.Visible : Visibility.Collapsed;
            }
            return Visibility.Collapsed;
        }

        // 将 Visibility 转换回布尔值
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Visibility visibility)
            {
                return visibility == Visibility.Visible;
            }
            return false;
        }
    }
}
